package com.itheima.reggie.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.reggie.entity.Category;
import com.itheima.reggie.mapper.CategoryMapper;
import com.itheima.reggie.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper,Category> implements CategoryService{

    @Autowired
    private CategoryMapper categoryMapper;

    @Override
    public IPage<Category> getCategoriesByPage(Integer page, Integer pageSize) {

        IPage<Category> categoryIPage = new Page<>();
        categoryIPage.setCurrent(page);
        categoryIPage.setSize(pageSize);

        return categoryMapper.selectPage(categoryIPage,null);
    }

    @Override
    public Boolean addCategory(Category category) {
        return categoryMapper.insert(category)>0;
    }
}
